package it.polito.connectedcar.tcc.zone;

import it.polito.connectedcar.tcc.TCCVehicleAbstraction;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author Nicola Aresta
 * 
 */
public class TokenLinkList {

	private List<TokenLink> tokenLinks;

	public TokenLinkList(List<TokenLink> tokenLinks) {
		this.tokenLinks = tokenLinks;
	}

	/**
	 * 
	 * @param tva
	 * @return
	 */
	public List<TokenLink> getTokenLink(TCCVehicleAbstraction tva) {
		List<TokenLink> tokenLinksList = new ArrayList<TokenLink>();
		for (TokenLink link : tokenLinks) {
			if (link.isUsefulFor(tva))
				tokenLinksList.add(link);
		}
		return tokenLinksList;
	}

	/**
	 * 
	 * @param t
	 * @return
	 */
	public TokenLink getTokenLink(Token t) {
		for (TokenLink link : tokenLinks) {
			if (link.getToken().equals(t))
				return link;
		}
		return null;
	}

	/**
	 * 
	 * @param tva
	 */
	public void remove(TCCVehicleAbstraction tva) {
		for (TokenLink link : tokenLinks) {
			link.getTransitVehicles().remove(tva);
		}
	}
}
